/*
 * Copyright (c) 2021, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "ti_msp_dl_config.h"
#include "main.h"
#include "stdio.h"


uint8_t oled_buffer[32];
uint8_t text[50]; 





int main(void)
{
    SYSCFG_DL_init();
    NVIC_ClearPendingIRQ(UART_OPENMV_INST_INT_IRQN);
    NVIC_EnableIRQ(UART_OPENMV_INST_INT_IRQN);
    SysTick_Init();
    MPU6050_Init();
    OLED_Init();
    


    //
	// uart0_init();	
	// TIMA0_init();
	// TIMG7_init();
	// encoder_init();
	// Bluetooth_Init();
	// delay_ms(10);
	// jy61pInit();
    // printf("while1\r\n");
    //


    /* Don't remove this! */
    Interrupt_Init();

    // OLED_ShowString(0,7,(uint8_t *)"MPU6050 Demo",8);
    OLED_ShowString(0,0,(uint8_t *)"Pitch",8);
    OLED_ShowString(0,2,(uint8_t *)" Roll",8);
    OLED_ShowString(0,4,(uint8_t *)"  Yaw",8);
    OLED_ShowString(16*6,3,(uint8_t *)"Accel",8);
    OLED_ShowString(17*6,4,(uint8_t *)"Gyro",8);
    // DL_GPIO_setPins(GPIO_laser_PORT,GPIO_laser_PIN_laser_PIN);
    uint32_t i = 980;
    // 6200
    while (1) 
    {

        // DL_TimerG_setCaptureCompareValue(PWM_0_INST,i,GPIO_PWM_0_C0_IDX);
        // i+=10;
        // // mspm0_delay_ms(0);
        // OLED_ShowNum(0, 7, i, 8, 8);
        // if(i >= 6200) {
        //     i = 980;
        //     DL_TimerG_setCaptureCompareValue(PWM_0_INST,i,GPIO_PWM_0_C0_IDX);
        //     mspm0_delay_ms(700);
        // }

        DL_TimerG_setCaptureCompareValue(PWM_0_INST,3590,GPIO_PWM_0_C0_IDX);

        // printf("ABC\r\n");
        //  draw_circle(8);
        // motor_rotate(360,1);

            // OLED_ShowHex(15*0, 2, mvbuf[0], 2, 8, 0);
            // OLED_ShowHex(15*1, 2, mvbuf[1], 2, 8, 0);
            // OLED_ShowHex(15*2, 2, mvbuf[2], 2, 8, 0);
            // OLED_ShowHex(15*3, 2, mvbuf[3], 2, 8, 0);
            // OLED_ShowHex(15*4, 2, mvbuf[4], 2, 8, 0);
            // OLED_ShowHex(15*5, 2, mvbuf[5], 2, 8, 0);
        // sprintf((char *)oled_buffer, "%-6.1f", pitch);
        // OLED_ShowString(5*8,0,oled_buffer,16);
        // sprintf((char *)oled_buffer, "%-6.1f", roll);
        // OLED_ShowString(5*8,2,oled_buffer,16);
        // sprintf((char *)oled_buffer, "%-6.1f", yaw);
        // OLED_ShowString(5*8,4,oled_buffer,16);
        // sprintf((char *)oled_buffer, "%6d", accel[0]);
        // OLED_ShowString(15*6,0,oled_buffer,8);
        // sprintf((char *)oled_buffer, "%6d", accel[1]);
        // OLED_ShowString(15*6,1,oled_buffer,8);
        // sprintf((char *)oled_buffer, "%6d", accel[2]);
        // OLED_ShowString(15*6,2,oled_buffer,8);
        // sprintf((char *)oled_buffer, "%6d", gyro[0]);
        // OLED_ShowString(15*6,5,oled_buffer,8);
        // sprintf((char *)oled_buffer, "%6d", gyro[1]);
        // OLED_ShowString(15*6,6,oled_buffer,8);
        // sprintf((char *)oled_buffer, "%6d", gyro[2]);
        // OLED_ShowString(15*6,7,oled_buffer,8);

		// DL_GPIO_togglePins(GPIO_laser_PORT,GPIO_laser_PIN_laser_PIN);	
		// delay_ms(400);

//		
//		DL_GPIO_togglePins(GPIO_TEST_PORT,GPIO_TEST_OUTtest_PIN);
		// key_fun();
//		if(key_count==1){
//			huidu_read();
//			xunji();
//		}
		// if(key_count==3){
		// 	ti3_fun();
		// }

		
		
//		if(HD1){
//			DL_GPIO_clearPins(GPIO_TEST_PORT,GPIO_TEST_BUZZER_PIN);
//		}
//		else	DL_GPIO_setPins(GPIO_TEST_PORT,GPIO_TEST_BUZZER_PIN);
		

//		if(TIMA0_flag){
//			TIMA0_flag=0;
//		}
		
	

    }
}
